/* 
 * File:   WindowManager.h
 * Author: johannes
 *
 * Created on December 19, 2013, 11:22 AM
 */

#ifndef WINDOWMANAGER_H
#define	WINDOWMANAGER_H

#include <SDL2/SDL.h>
#include <map>
#include <utility>
#include <string>

#include "angelscript.h"

#include "Utility.h"
#include "SDLLib.h"

namespace GUL {
    namespace System {
        namespace Graphic {

            class Window;
            class VideoManager {
            private:
                Windows m_WindowDictionary;
                SDLLib m_SDLinit;
                
                unsigned m_referenceCount;

            protected:

                
                
//                std::string at(int index);

            public:
                VideoManager();
                VideoManager(const std::string& Name, UPair Pos, UPair Boundary, Uint32 flags);
                virtual ~VideoManager();
                static void AddScriptEngine(asIScriptEngine* engine) ;


//                Window& at(const char*);
                Window& at(const std::string&);
                
                void AddRef(){this->m_referenceCount++;}
                void ReleaseRef(){this->m_referenceCount--;};

                
                void Create1(const std::string& Name, UPair Pos, UPair Boundary, Uint32 flags);
                void Create(const std::string& Name, int x,int y,int w,int h,Uint32 flags);
                void Destroy(const std::string&);

                Window& operator [](const std::string&);
                std::string operator [](int index) {
                    return this->VideoDriver(index);
                }

                Windows& operator ()() {
                    return this->m_WindowDictionary;
                }


                int NumVideoDrivers();
                int NumVideoDisplays();
                int DisplayBounds(int display, SDL_Rect* rect);
                std::string DisplayName(int displayindex);
                std::string VideoDriver(int index);
                std::string CurrentVideoDriver();

                void shutdown();
                void startup(const std::string& drivername);

                void GL_LoadLibrary(const std::string&) const;
                void* GL_GetProcAddress(const std::string&) const;
                void GL_UnloadLibrary() const;
                bool GL_ExtensionSupported(const std::string&) const;
                int GL_SetAttribute(SDL_GLattr attr, int val) const;
                int GL_GetAttribute(SDL_GLattr attr, int* val) const;
                int GL_MakeCurrent(const std::string& Windowname, SDL_GLContext cont);
                Window& GL_GetCurrentWindow();
                SDL_GLContext GL_GetCurrentContext() const;
                void GL_GetDrawableSize(const std::string& Windowname, int*w, int *h);
                void GL_SetSwapInterval(int interval) const;
                int GL_GetSwapInterval() const;
                void GL_SwapWindow(const std::string& Windowname);
                void GL_DeleteContext(SDL_GLContext context);
                SDL_GLContext GL_CreateContext(const std::string& window);

            };
            
             VideoManager* FactoryVideoManager();
//            static VideoManager* FactoryVideoManagerCopy(const VideoManager& copy);
             void          VideoManagerRelease(VideoManager* obj);
            
        }
    }
}


#endif	/* WINDOWMANAGER_H */

